function addformreservation()
{
$("#addform").append('<div id="feature'+rowdiv+'" class="itPlg addHshPlug featureclass">'+dataform['reservation']+"</div>");
var rownow=rowdiv;
   $('#feature'+rownow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();
    
   });
rowdiv++;

}

function checkuserconfirm(idresv,productid)
{
var statusset=1;
if($("#checkuser-"+idresv).is(':checked'))
{

     statusset=2;

}else
{
    statusset=1;

}
var parem=new Array();
parem[0]=idresv;
parem[1]=productid;
parem[2]=statusset;

loaddata();
$.get(serviceinfo+'getmedthodplugin', { classset:'reservation',medthodset:'confirmreservation',parem:parem }, function(data) { 
loadclosedata();
if(data.error.response)
{
if(data.error.error[0].code==5)
{
$('.ovlPopLd').hide();
$('.wrpPopSU').fadeIn();

}else
{
boxmsgdata(data.error.error[0].msg);

}


}else
{

   if(statusset==1)
   {
   
   $(".wrpWaitRgt .lstWait").append($("#liuser-"+idresv));
   }else
   {
   $(".wrpCfmRgt .lstCfm").append($("#liuser-"+idresv));
   
   }
   countelementbox();



}
});


}

function deleteuserconfirm(idresv,productid)
{

boxconfirmmsgdata('Delete ?','deleteuserconfirmset',idresv+','+productid);



}

function exportuserreservationlist(productid,status)
{
var statusset=0;
if(status)
{
statusset=status;
}

location.href=serviceinfo+'getmedthodplugin?classset=reservation&medthodset=exportuser&parem[]='+productid+'&parem[]='+statusset+'&nojson=1';




}

function deleteuserconfirmset(idresv,productid)
{



var parem=new Array();
parem[0]=idresv;
parem[1]=productid;


loaddata();
$.get(serviceinfo+'getmedthodplugin', { classset:'reservation',medthodset:'deleteuserreservation',parem:parem }, function(data) { 
loadclosedata();
if(data.error.response)
{
if(data.error.error[0].code==5)
{
$('.ovlPopLd').hide();
$('.wrpPopSU').fadeIn();

}else
{
boxmsgdata(data.error.error[0].msg);

}


}else
{

   $("#liuser-"+idresv).remove();
   countelementbox();



}
});


}

function countelementbox()
{
;
$(".countwaitinglist").html($(".wrpWaitRgt .lstWait li").length);
$(".countconfirmlist").html($(".wrpCfmRgt .lstCfm li").length);

}

function getformreservation(dataplugin)
{
var code = '<div class="ldIt wrpFrmLd clBg4">\n';
code += '<div class="wrpHdInfoGen mgBtm10">\n';
code += '<h2 class="clTxt2 fs04 boldGen">Reservation</h2>\n';
code += '</div>\n';
code += '<div class="wrpRsv bdBtm clBd2">\n';
code += '<div class="rsvBtnJoin clBgSp2" onclick="savereservedata('+dataplugin.productid+')">\n';
code += '<span class="clTxtW fs11">JOIN THIS !!!</span>\n';
code += '</div>\n';
code += '<div class="cpltRsv fs04 clTxt2">To complete reservation, you must confirmation via your email address.</div>\n';
code += '</div>\n';

if(dataplugin['checkmy']||roleidinfo==3)
{
var str1="";
var krow1=0;
var str2="";
var krow2=0;
var checkuserre="";

if(dataplugin['userlist'].length)
{
$.each(dataplugin['userlist'], function(key, value) {

checkuserre='';
if(value['status']=='2')
{
checkuserre=' checked="checked" ';
}

var code1 = '<li class="clearfix">\n';
code1 += '<div class="rgtName">\n';
code1 += '<input id="checkuser-'+value['resvid']+'"  '+checkuserre+' type="checkbox" onclick="checkuserconfirm('+value['resvid']+','+dataplugin.productid+')" >\n';
code1 += '<a href=""><img width="24" height="24" alt="img" src="'+value['userssimg']['newpath']+'" class="genImgUser">\n';
code1 += '<span class="cutTxt">'+value['displayname']+'</span></a>\n';
code1 += '</div>\n';
code1 += '<span class="rgtInfo rgsDelRsv" onclick="deleteuserconfirm('+value['resvid']+','+dataplugin.productid+')" >\n';
code1 += '<em class="ico icoDelRsv"></em>\n';
code1 += '</span>\n';
code1 += '<span class="rgtInfo rgtInfoRsv" onclick="openaddreservation(\''+value['displayname']+'\',\''+value['email']+'\',\''+value['phone']+'\')" >\n';
code1 += '<em class="ico icoInfoRsv"></em>\n';
code1 += '</span>\n';
code1 += '</li>';

if(value['status']=='1')
{
str1+=code1;
krow1++;

}else
{
str2+=code1;
krow2++;

}



});


}


code += '<div class="wrprRgtCfm clearfix">\n';
code += '<div class="wrpWaitRgt clBd2 bdR">\n';
code += '<div class="wrpHdWaitRgt clearfix">\n';
code += '<h2 class="boldGen fs04 clTxt2">Waiting List (<span class="countwaitinglist">'+krow1+'</span>/'+dataplugin.reserve+')</h2>\n';

code += '<input type="submit" class="btnEPRsv clBgBt1" onclick="exportuserreservationlist('+dataplugin['productid']+',1)" value="">\n';
code += '<input type="submit" class="btnMail clBgBt1" onclick="emailuserreservationlist('+dataplugin['productid']+',1)" value="">\n';
code += '</div>\n';
 code+= '<ul class="lstWait">\n';

code+=str1;

code += '</ul>\n';
code += '</div>\n';
code += '<div class="wrpCfmRgt">\n';
code += '<div class="wrpHdWaitRgt clearfix">\n';
code += '<h2 class="boldGen fs04 clTxt2">Confirmation List (<span class="countconfirmlist">'+krow2+'</span>/'+dataplugin.seat+')</h2>\n';
code += '<input type="submit" class="btnEPRsv clBgBt1" onclick="exportuserreservationlist('+dataplugin['productid']+',2)" value="">\n';
code += '<input type="submit" class="btnMail clBgBt1" onclick="emailuserreservationlist('+dataplugin['productid']+',2)" value="">\n';
code += '</div>\n';
code += '<ul class="lstCfm">\n';

code+=str2;

code += '</ul>\n';
code += '</div>\n';
code += '</div>';



}


return code;






}
var firstemailuser=1;
function emailuserreservationlist(productid,status)
{
$('.wrpPopSendMail').fadeIn();
if(firstemailuser)
{
firstemailuser=0;
$('#frombroadcast2').submit(function() {
if($('#txtbroadcast2').val())
{
var parem=new Array();
parem[0]=productid;
parem[1]=status;
parem[2]=$('#txtbroadcast2').val();
parem[3]=$('#titleemail').val();

loaddata();
$.post(serviceinfo+'postmedthodplugin', { classset:'reservation',medthodset:'emailreseruser',parem:parem }, function(data) { 

loadclosedata();
if(data.error.response)
{

boxmsgdata(data.error.error);

//alertboxtext(data.error.error,$("#validateerror-login"));

}else
{
boxmsgdata('Success');
//$('#txtbroadcast2').val('');
//location.href=baseinfo;


}


});


}
return false;
});
}

}

function openaddreservation(userset,email,tel)
{

var code = '<div class="wrpMiniPop clBgBt1">\n';
code += '<div class="miniPop">\n';
code += '<span class="txtMiniPop txtSUMiniPop fs03 clTxtW">'+userset+'<br></span>\n';
code += '<span class="txtMiniPop txtSUMiniPop fs03 clTxtW">Tel: <em>'+tel+'</em><br></span>\n';
code += '<span class="txtMiniPop txtSUMiniPop fs03 clTxtW">Email: <em>'+email+'</em></span>\n';
code += '<div class="wrpBtnMiniPop">\n';
code += '<span class="btnIco btnMiniPop btnOK clTxtW fs03" onclick="$(\'.wrprMiniPop.wrpPopMiniRgt\').fadeOut()">OK</span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';

$(".wrprMiniPop.wrpPopMiniRgt").html(code);
$(".wrprMiniPop.wrpPopMiniRgt").fadeIn();


}
var productidsetres=0;
function savereservedata(productid)
{
productidsetres=productid;
var parem=new Array();
parem[0]=productid;
loaddata();
$.get(serviceinfo+'getmedthodplugin', { classset:'reservation',medthodset:'savereservedata',parem:parem }, function(data) { 
loadclosedata();
if(data.error.response)
{
if(data.error.error[0].code==34)
{
$('.wrprMiniPop.wrpPopMiniTel').fadeIn();

}else
{


if(data.error.error[0].code==5)
{
$('.ovlPopLd').hide();
$('.wrpPopSU').fadeIn();

}else
{
boxmsgdata(data.error.error[0].msg);

}

}


}else
{

boxmsgdata('Success');

}

});


}

function saveformreservation(id,plugid)
{
    var obj={};
    var unseat=0;
    if($("#"+id+' input[name="unseat[]"]').is(':checked'))
    {
         unseat=1;
    
    }
    
    
    var unreser=0;
    if($("#"+id+' input[name="unreser[]"]').is(':checked'))
    {
         unreser=1;
    
    }
    
    
    obj={plugid:plugid,
    seat:$("#"+id+' input[name="seat[]"]').val(),
    unseat:unseat,
    unreser:unreser,
    premium:$("#"+id+' input[name="premium[]"]:checked').val(),
    reserve:$("#"+id+' input[name="reserve[]"]').val()
    
    
    
    };
    return obj;

}
function editformreservation(datarow)  
{
    addformreservation();
    var rownow= rowdiv-1;
    $('#feature'+rownow+' input[name="seat[]"]').val(datarow.seat);
    $('#feature'+rownow+' input[name="reserve[]"]').val(datarow.reserve);
    
    if(datarow.unseat!="0")
    {
        $('#feature'+rownow+' input[name="unseat[]"]').attr('checked', 'checked');
    }
    
    if(datarow.unreser!="0")
    {
        $('#feature'+rownow+' input[name="unreser[]"]').attr('checked', 'checked');
    }

    //$('#feature'+rownow+' input[name="unreser[]"]').val(datarow.reserve);
    if(datarow.premium=='1')
    {
    $('#feature'+rownow+' .checkdata2').attr('checked', 'checked');
    }else
    {
    $('#feature'+rownow+' .checkdata1').attr('checked', 'checked');
    
    }
    

}